package com.qzyh.esb.egsa.utils;


import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Data
public class PageResultObject<T> implements Serializable {

    static SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");

    public static final String DEFAULT_SUCCESS_CODE = "000000";

    public static final String DEFAULT_SUCCESS_MSG = "SUCCESS";


    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /**
     * 时间戳
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String timestamp;
    /**
     * 响应状态
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String code;
    /**
     * 响应描述
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String message;

    private Long total;

    private Long pageNum;

    private Long pageSize;
    /**
     * 响应数据
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private List<T> data;

    public PageResultObject() {

    }

    /**
     * 若没有数据返回，可以人为指定状态码和提示信息
     */
    public PageResultObject(String code, String message) {
        this.timestamp = sdf.format(new Date());
        this.code = code;
        this.message = message;
    }

    public static <T> PageResultObject<T> success() {
        return new PageResultObject<>(DEFAULT_SUCCESS_CODE, DEFAULT_SUCCESS_MSG);
    }

}
